<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //创建一个具有缓存效果的纯函数
        function cached(fn){
            var cache = Object.creat(null)
            return function cachedFn(str){
                var hit = cache[str]
                return hit || (cache[str]= fn(str))
            }
        }
        //封装一个函数求1到num之间的和
        function sum(num){
            let total = 0;
            for(let i = 1; i <= num ;i++){
                total += i
            }
            return cacheSum = cached(sum)
            console.log(cacheSum(1000))
        }
    </script>
</body>
</html>